//---------------------------------------------------------------------------------------------------------------------------------------------------
// <copyright file="GameController.cs" company="DarkWynter Studios">
//     Copyright (C)2007 DarkWynter Studios.  All rights reserved.
// </copyright>
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------

namespace DWControllerDemo
{
    #region Using Statements
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Input;

    using DarkWynter.Engine.Controllers;

    #endregion

    /// <summary>
    /// Game Controller for getting player inputs in-game
    /// </summary>
    public class GameController : Controller
    {
        /// <summary>
        /// Constructor for PC and mouse controls
        /// </summary>
        /// <param name="playerNumber">Player index for this controller</param>
        public GameController(int playerNumber): base(playerNumber)
        {
            Add(new KeyboardControl(Keys.Escape, Escape, 3000));
            Add(new KeyboardControl(Keys.M, SwitchGameMode, 100));
            
            Add(new KeyboardControl(Keys.W, MoveForward, 10));
            Add(new KeyboardControl(Keys.A, MoveLeft, 10));
            Add(new KeyboardControl(Keys.D, MoveRight, 10));
            Add(new KeyboardControl(Keys.S, MoveBackward, 10));

            Add(new KeyboardControl(Keys.Up, ChangeColorPos, 100));
            Add(new KeyboardControl(Keys.Down, ChangeColorNeg, 100));
        }
        /// <summary>
        /// Constructor for Xbox only controls
        /// </summary>
        /// <param name="playerIndex"></param>
        public GameController(PlayerIndex playerIndex)
            : base(playerIndex)
        {
            // Add xbox controls
        }
        /// <summary>
        /// Constructor for Xbox and keyboard controls
        /// </summary>
        /// <param name="player">Player index in ObjectLibrary</param>
        /// <param name="playerIndex">Player index for this controller</param>
        public GameController(int player, PlayerIndex playerIndex)
            : base(player, playerIndex)
        {
            Add(new KeyboardControl(Keys.Escape, Escape, 3000));
            Add(new KeyboardControl(Keys.M, SwitchGameMode, 100));

            Add(new KeyboardControl(Keys.W, MoveForward, 0));
            Add(new KeyboardControl(Keys.A, MoveLeft, 0));
            Add(new KeyboardControl(Keys.D, MoveRight, 0));
            Add(new KeyboardControl(Keys.S, MoveBackward, 0));

            Add(new KeyboardControl(Keys.Up, ChangeColorPos, 100));
            Add(new KeyboardControl(Keys.Down, ChangeColorNeg, 100));
        }


        private void Escape(ControllerBoolEventArgs args)
        {
            ControllerDemo._self.Exit();
        }
        private void SwitchGameMode(ControllerBoolEventArgs args)
        {
            ControllerDemo._self.gameMode = ControllerDemo.GameMode.Menu;
        }
        private void MoveForward(ControllerBoolEventArgs args)
        {
        }
        private void MoveBackward(ControllerBoolEventArgs args)
        {
        }
        private void MoveLeft(ControllerBoolEventArgs args)
        {
        }
        private void MoveRight(ControllerBoolEventArgs args)
        {
        }

        private void ChangeColorPos(ControllerBoolEventArgs args)
        {
            Vector4 color = ControllerDemo._self.backColor.ToVector4();
            color.X += .1f;         // R
            color.Y -= .1f;         // G
            color.Z += .3f;         // B
            ControllerDemo._self.backColor = new Microsoft.Xna.Framework.Graphics.Color(color);
        }
        private void ChangeColorNeg(ControllerBoolEventArgs args)
        {
            Vector4 color = ControllerDemo._self.backColor.ToVector4();
            color.X -= .1f;         // R
            color.Y += .1f;         // G
            color.Z -= .3f;         // B
            ControllerDemo._self.backColor = new Microsoft.Xna.Framework.Graphics.Color(color);
        }
    }
}
